﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Wicresoft.Common;
using Wicresoft.Framework.Organization;
using JDEduTrain.Framework.Business;
using JDEduTrain.Framework.Entity;


public partial class Page_AddScore : BaseAuthenticationPage
{
    private Guid MemberID
    {
        get
        {
            if (Request["MemberID"] != null)
            {
                return new Guid(Request["MemberID"]);

            }
            return Guid.Empty;
        }
    }

    protected DataTable DTClassOrder
    {
        get
        {
            if (ViewState["DTClassOrder"] != null)
            {
                return (DataTable)ViewState["DTClassOrder"];
            }
            return new DataTable();
        }
        set
        {
            ViewState["DTClassOrder"] = value;
        }
    }



    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "增加额外学分";


        if (!IsPostBack)
        {
        }
    }

    protected void lbtnSave_Click(object sender, EventArgs e)
    {
        ExtraCredit credit = new ExtraCredit();
        credit.ID = Guid.NewGuid();
        credit.BeginTime = string.IsNullOrEmpty(tbBeginTime.Text) ? DateTime.MinValue : DateTime.Parse(tbBeginTime.Text);
        credit.EndTime = string.IsNullOrEmpty(tbEndTime.Text) ? DateTime.MinValue : DateTime.Parse(tbEndTime.Text);
        credit.PassTime = string.IsNullOrEmpty(tbPassTime.Text) ? DateTime.MinValue : DateTime.Parse(tbPassTime.Text);
        credit.MainContent = tbMainContent.Text;
        float trainday = 0;
        float.TryParse(tbTrainDayCount.Text, out trainday);
        credit.TrainDayCount = trainday;
        credit.HostUnit = tbHostUnit.Text;
        credit.MemberID = MemberID;
        float score = 0;
        float.TryParse(tbCourseScore.Text,out score);
        credit.Score = score;
        credit.TrainLevel = ddlTrainLevel.SelectedValue;
        credit.TrainName = tbCreditName.Text;
        credit.Save();

        MemberTrainDetail memberTrainDetail = new MemberTrainDetail();
        memberTrainDetail.BeginTime = credit.BeginTime;
        memberTrainDetail.ClassName = credit.TrainName;
        memberTrainDetail.CreditHour = 0;
        memberTrainDetail.ID = Guid.NewGuid();
        memberTrainDetail.MainDepartmentID = OrganizationHelper.GetUserInfo(MemberID).MainDepartmentID;
        memberTrainDetail.MemberID = MemberID;
        memberTrainDetail.PassTime = credit.PassTime.Year;
        memberTrainDetail.Score = credit.Score;
        memberTrainDetail.TrainLevel = credit.TrainLevel;
        memberTrainDetail.CreditID = credit.ID;
        memberTrainDetail.Save();

        string script = "<script>alert('保存成功!');refreshParent();window.close();</script>";
        ClientScript.RegisterStartupScript(this.GetType(), "Close", script);
    }

}
